package com.riteny.common.entity;

import com.riteny.common.httpclient.CommonHttpRestfulTemplate;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author Riteny
 * 2021/10/22  11:27
 */
public class CommonHttpParamArrayNode extends ArrayList implements CommonHttpParamNode {

    private CommonHttpParamNode prevNode;

    private CommonHttpRestfulTemplate httpRestfulTemplate;


    public CommonHttpParamArrayNode(CommonHttpRestfulTemplate httpRestfulTemplate) {
        this.httpRestfulTemplate = httpRestfulTemplate;
    }

    public CommonHttpParamArrayNode addParam(String value) {

        add(value);

        return this;
    }

    public CommonHttpParamArrayNode addParams(List values) {

        addAll(values);

        return this;
    }

    public CommonHttpParamMapNode addMapNode() {

        CommonHttpParamMapNode newNode = new CommonHttpParamMapNode(httpRestfulTemplate);
        newNode.setPrevNode(this);

        add(newNode);

        return newNode;
    }

    public CommonHttpParamArrayNode addArrayNode() {

        CommonHttpParamArrayNode newNode = new CommonHttpParamArrayNode(httpRestfulTemplate);
        newNode.setPrevNode(this);

        add(newNode);

        return newNode;
    }

    public CommonHttpParamMapNode prevMapNode() {
        return (CommonHttpParamMapNode) prevNode;
    }

    public CommonHttpParamArrayNode prevArrayNode() {
        return (CommonHttpParamArrayNode) prevNode;
    }

    public void setPrevNode(CommonHttpParamNode prevNode) {
        this.prevNode = prevNode;
    }

    public CommonHttpRestfulTemplate and() {
        return httpRestfulTemplate;
    }

    public void setHttpRestfulTemplate(CommonHttpRestfulTemplate httpRestfulTemplate) {
        this.httpRestfulTemplate = httpRestfulTemplate;
    }
}
